﻿<Window x:Class="TfsUtil.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d"
        xmlns:cmd="clr-namespace:TfsUtil.Commands" xmlns:local="clr-namespace:TfsUtil" Title="MainWindow" Height="350"
        Width="525" WindowStartupLocation="CenterScreen" FontFamily="{StaticResource DefaultFontFamily}"
        FontSize="{StaticResource DefaultFontSize}" MinWidth="450" MinHeight="450"
        SizeToContent="Manual">
    <Window.Resources>
        <BitmapImage x:Key="CloseTabImageSource"
                UriSource="pack://application:,,,/TfsUtil;component/Resources/CloseTab.png" />
        <DataTemplate x:Key="TabItemHeaderTemplate" DataType="local:ContentTabViewModel">
            <StackPanel Orientation="Horizontal"
                    DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=TabItem},Path=DataContext}"
                    d:DataContext="{d:DesignInstance local:ContentTabViewModel}">
                <TextBlock Text="{Binding HeaderText}" VerticalAlignment="Center" />
                <Button Margin="5,5,5,5" VerticalAlignment="Center" IsTabStop="False" ClickMode="Release"
                        Command="cmd:AppCommands.CloseActiveContent"
                        CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=TabItem}}"
                        Focusable="False">
                    <Button.Template>
                        <ControlTemplate TargetType="Button">
                            <StackPanel x:Name="ButtonContentPanel">
                                <ContentPresenter Content="{TemplateBinding Content}" />
                            </StackPanel>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsMouseOver" Value="true">
                                    <Setter TargetName="ButtonContentPanel" Property="Background">
                                        <Setter.Value>
                                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                <GradientBrush.GradientStops>
                                                    <GradientStopCollection>
                                                        <GradientStop Color="#FFF" Offset="0.0" />
                                                        <GradientStop Color="#AAA" Offset="1.0" />
                                                    </GradientStopCollection>
                                                </GradientBrush.GradientStops>
                                            </LinearGradientBrush>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                                <Trigger Property="IsPressed" Value="true">
                                    <Setter TargetName="ButtonContentPanel" Property="Background">
                                        <Setter.Value>
                                            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                <GradientBrush.GradientStops>
                                                    <GradientStopCollection>
                                                        <GradientStop Color="#BBB" Offset="0.0" />
                                                        <GradientStop Color="#EEE" Offset="0.1" />
                                                        <GradientStop Color="#EEE" Offset="0.9" />
                                                        <GradientStop Color="#FFF" Offset="1.0" />
                                                    </GradientStopCollection>
                                                </GradientBrush.GradientStops>
                                            </LinearGradientBrush>
                                        </Setter.Value>
                                    </Setter>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Button.Template>
                    <Image Source="{StaticResource CloseTabImageSource}" />
                </Button>
            </StackPanel>
        </DataTemplate>
    </Window.Resources>
    <Window.DataContext>
        <local:MainWindowViewModel x:Name="ViewModel" x:FieldModifier="public" />
    </Window.DataContext>
    <Window.CommandBindings>
        <CommandBinding Command="cmd:AppCommands.NewMergeSearch" CanExecute="CanExecuteMergeSearch"
                Executed="ExecuteMergeSearch" />
        <CommandBinding Command="cmd:AppCommands.CloseActiveContent" CanExecute="CanCloseActiveContent"
                Executed="ExecuteCloseActiveContent" />
    </Window.CommandBindings>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Menu Grid.Row="0" Height="23" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                FontFamily="Verdana" FontSize="11">
            <MenuItem Name="FileMenu" Header="_File">
                <MenuItem Name="MergeSearchMenuItem" Header="New _Merge Search..." Command="cmd:AppCommands.NewMergeSearch" />
                <MenuItem Name="CloseMenuItem" Header="_Close" Command="cmd:AppCommands.CloseActiveContent" />
            </MenuItem>
            <MenuItem Name="ServerMenu" Header="_Server" />
        </Menu>
        <ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
            <TabControl Name="ContentTabs" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <TabControl.Resources>
                    <Style TargetType="TabItem">
                        <Setter Property="HeaderTemplate" Value="{StaticResource TabItemHeaderTemplate}" />
                    </Style>
                </TabControl.Resources>
            </TabControl>
        </ScrollViewer>
    </Grid>
</Window>